<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/10/22
 * Time: 11:16
 */
require('../conn.php');
require('../functions.php');
require('../QueryList.class.php');
if ($_POST) {
    $post = $_POST;
    $uid = $post['uid'];
    $url = $post['url'];
    //判断用户状态
    $user = $mysql->query("select `ban` from `user` WHERE `id`={$uid}");
    $state = $user[0]['ban'];
    if ($state != 0) {
        $data = [
            'success' => 0,
        ];
        echo json_encode($data);
    } else {
        //抓取秒拍视频
        $html = get_contentsM($url);
        $reg = [
            'title' => ['p:first', 'text'],
            'video' => ['.video_player', 'html'],
            'pic' => ['.vid_img', 'html'],
        ];
        $hj = QueryList::Query($html, $reg);
        $arr = $hj->jsonArr;
//获取video的src
        $videoStr = $arr[0]['video'];
        $str = 'yx=&amp;refer=weibo_app" preload="preload">';
        $replaceStr = cut($videoStr, "?", '""');
        $content = str_replace($replaceStr, $str, $videoStr);
        $video = cut($content, "src=\"", "\"");
//获取缩略图
        $picDiv = $arr[0]['pic'];
        $pic = cut($picDiv, 'data-url="', '"');
//获取标题
        $title = $arr[0]['title'];
        $videoSource = [
            'uid' => $uid,
            'title' => $title,
            'img' => $pic,
            'video' => $video,
            'day' => date("Y-m-d H:i:s"),
        ];
        $mysql->execute("insert into `video_resolve`" . arr2s($videoSource));
        $id = mysql_insert_id();
        $data = [
            'success' => 1,
            'img' => $pic,
            'title' => $title,
            'id' => $id,
        ];
        echo json_encode($data);
    }
}
